import Vue from 'vue'
// 引入element-ui框架
import ElementUI from 'element-ui'
// 引入公共element-ui的css样式表
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import Axios from './config/axios'
import Qs from 'qs'
import hasPermission from './config/hasPermission'
// import VueAxios from 'vue-axios'

// 后台登录控制模块
router.beforeEach(async(to, from, next) => {
    if (localStorage.getItem('express_admin_token') && localStorage.getItem('express_admin_id')) {
        if (to.path === '/admin/login') {
            next({ path: '/admin/home/index' })
        } else {
            next()
        }
    } else {
        if (to.path === '/admin/login') {
            next()
        } else {
            next(`/admin/login?redirect=${to.path}`)
        }
    }
})

Vue.config.productionTip = false

Vue.prototype.$axios = Axios // 使用axios框架
Vue.prototype.$qs = Qs // 使用axios框架

// 使用element-ui框架
Vue.use(ElementUI);
Vue.use(hasPermission)


/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    render: h => h(App)
})